package io.renren.common.interceptor;

import io.renren.modules.nuaa.entity.TUserEntity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 登录拦截器
 *
 * @author whc
 */
@Component
public class MyLoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Session session = SecurityUtils.getSubject().getSession();
        TUserEntity userEntity = (TUserEntity) session.getAttribute("userInfo");
        System.out.println(request.getRequestURL());
        if(userEntity!=null){
            return true;
        }else{
            response.sendRedirect("/h5/login");
            return false;
        }
    }

}
